package com.hruiworks.campusgroup.config;


import com.hruiworks.campusgroup.Interceptor.AdministratorInterceptor;
import com.hruiworks.campusgroup.Interceptor.UserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class SpringMvcConfig implements WebMvcConfigurer{

    @Resource
    private UserInterceptor userInterceptor;

    @Resource
    private AdministratorInterceptor administratorInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userInterceptor).addPathPatterns("/**").excludePathPatterns("/api/user/login","/api/user/register","/api/administrator/**","/api/test/**");
        registry.addInterceptor(administratorInterceptor).addPathPatterns("/api/administrator/**").excludePathPatterns("/api/administrator/login","/api/test/**");
    }

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedOrigins("http://localhost:5173") // Explicitly allow your frontend origin
//                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
//                .allowedHeaders("*")
//                .allowCredentials(true); // Allow credentials
//    }
}
